package com.example.fp.zlz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.fp.zlz.entity.Admin;
import com.example.fp.zlz.entity.Userinfo;
import com.example.fp.zlz.entity.Useronline;
import com.example.fp.zlz.entity.Usertoken;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 说明: 用户表操作接口
 * 编写人: 张连壮
 * 编写时间: 2019-12-31
 * 修改时间:
 * 接口
 */
@Mapper
public interface AdminMapper extends BaseMapper<Admin> {
	@Select("select count(*) from user where username =#{username} and password=#{password}")
	int selectadmin(Admin admin);
	@Select("select count(*) from user where username =#{username}")
	int selectadminbyname(Admin admin);
	@Update("update user set token =#{token},online =#{online} where username =#{username}")
	void updatetokenbyname(Admin admin);
	@Select("select token from user where username =#{username}")
	String selecttokenbyname(String username);
	@Select("select username,token from user")
	List<Usertoken> selecttoken();
	@Select("select * from user where id =#{id}")
	Userinfo selectuserinfo(Admin admin);
	@Update("update user set pic =#{pic} where id =#{id}")
	void updatepic(Admin admin);
	@Update("update user set bg =#{bg} where id =#{id}")
	void updatebg(Admin admin);
//测试中
	//登陆用
	@Select("select * from user where username =#{username}")
	Userinfo selectbyusername(String username);
	//
	@Select("select * from user where id =#{id}")
	Userinfo selectbyuid(int id);
	//退出登录
	@Update("update user set online =false where username =#{username}")
	void lgoutsetsession(String username);
	//在线状态
	@Select("select id,username,phone,email,pic,online from user")
	List<Useronline> selectuseronline();

	/**
	 * 设置所以用户为离线状态
	 * @since 2020-03-05
	 * @author 蔡
	 */
	@Update("update user set online = false")
	void setOffLine();
}
